package com.手写线程池.线程池消费端;

import com.手写线程池.拒绝策略设计.RejectPolicy;
import com.手写线程池.阻塞队列.BlockingQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Fang Ruichuan
 * @date 2023-01-28 21:21
 */
public class TestThreadPool1 {

    private static Logger LOGGER = LoggerFactory.getLogger(TestThreadPool1.class);

    public static void main(String[] args) throws InterruptedException {
        Executor executor = new ThreadPool(2, 4, new RejectPolicy() {
            @Override
            public void reject(BlockingQueue queue, Object task) {
                LOGGER.error("task too much");
            }
        });
        // 提交任务
        for (int i = 0; i < 6; i++) {
            final int j = i;
            executor.execute(() -> {
                try {
                    Thread.sleep(10);
                    LOGGER.info("run task {}", j);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            Thread.sleep(10);
        }
        Thread.sleep(10000);
    }
}
